package com.lanou.musicbox.adapter.skin;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.musicbox.R;
import com.lanou.musicbox.bean.MineSkin;
import com.lanou.musicbox.custom.Image;

import java.util.List;

/**
 * Created by dllo on 15/10/31.
 */
public class SkinGridViewAdapter extends BaseAdapter{
    private Context context;
    private List<MineSkin>data;
    private int currentId=-1;

    public SkinGridViewAdapter(Context context,List<MineSkin>data,int currentId){
        this.context=context;
        this.data=data;
        this.currentId=currentId;
    }
    public  void setCurrentId(int currentId){
        this.currentId=currentId;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return data!=null&&data.size()>0?data.size():0;
    }

    @Override
    public Object getItem(int position) {
        return data!=null&&data.size()>0?data.get(position):0;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView= LayoutInflater.from(context).inflate(R.layout.skin_render_item,null);
        viewHolder=new ViewHolder();
            viewHolder.skin_wallpager= (ImageView) convertView.findViewById(R.id.skin_wallpager);
            viewHolder.skin_title= (TextView) convertView.findViewById(R.id.skin_title);
            convertView.setTag(viewHolder);

        }else{
            viewHolder= (ViewHolder) convertView.getTag();
        }
        //判断是否为同一个背景颜色
        if (position==currentId){
            viewHolder.skin_wallpager.setImageDrawable(Image.createSelectedTip(context,data.get(position).getSkinImgResId(),R.mipmap.skin_checked));
        }else{
            viewHolder.skin_wallpager.setImageResource(data.get(position).getSkinImgResId());
        }
        viewHolder.skin_title.setText(data.get(position).getSkinTitleResID());
        return convertView;
    }
    class  ViewHolder{
        private ImageView skin_wallpager;
        private TextView skin_title;

    }
}
